package com.lagou.controller;

import com.lagou.service.CodeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName CodeController
 * @Description
 * @Author playboy
 * @Date 2021/6/25 6:14 下午
 * @Version 1.0
 **/
@RestController
@RequestMapping("/code")
public class CodeController {
	private static Logger log = LoggerFactory.getLogger(CodeController.class);

	@Autowired
	private CodeService codeService;

	/**
	 * 对给定的邮箱发送验证码
	 *
	 * @param email
	 * @return
	 */
	@RequestMapping("/create/{email}")
	public boolean create(@PathVariable("email") String email) {
		boolean result = true;
		try {
			result = codeService.create(email);
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		return result;
	}

	@RequestMapping("/validate/{email}/{code}")
	public Integer validate(@PathVariable("email") String email, @PathVariable("code") String code) {
		return codeService.validate(email, code);
	}
}
